package com.fis.vaadin.util;

import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Vector;

import com.fis.mca.MainApplication;
import com.fis.mca.MainWindow;
import com.fis.mca.admin.AppClient;
import com.fis.mca.admin.AppUser;
import com.fss.ddtp.DDTP;

public class LogUtil
{
	public static void logAccess(String moduleName)
	{
		
		try
		{
			DDTP request = new DDTP();
			request.setString("strModule", moduleName);
			request.setString("ipAddress", AppClient.getIpRemoteAddr());
			AppClient.sendRequest("AccessLogViewerBean", "logModuleAccess",
					request);
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
	
	public static void logActionInsert(String moduleName, String tableName,
			String primaryKeyName, String primaryKeyValue,
			Vector<Vector<String>> vObjectRelated)
	{
		try
		{
			DDTP request = new DDTP();
			request.setObject("ipAddress", AppClient.getIpRemoteAddr());
			request.setString("primaryKeyValue", primaryKeyValue);
			request.setString("primaryKeyName", primaryKeyName);
			request.setString("tableName", tableName);
			request.setString("moduleName", moduleName);
			request.setObject("vObjectRelated", vObjectRelated);
			AppClient.sendRequest("CommonActionLog", "logInsert", request);
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
	
	public static void logActionDelete(String moduleName, String tableName,
			String primaryKeyName, String primaryKeyValue,
			Vector<Vector<String>> vObjectRelated)
	{
		try
		{
			DDTP request = new DDTP();
			request.setObject("ipAddress", AppClient.getIpRemoteAddr());
			request.setString("primaryKeyValue", primaryKeyValue);
			request.setString("primaryKeyName", primaryKeyName);
			request.setString("tableName", tableName);
			request.setString("moduleName", moduleName);
			request.setObject("vObjectRelated", vObjectRelated);
			AppClient.sendRequest("CommonActionLog", "logDelete", request);
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
	
	public static Vector logActionBeforeUpdate(String moduleName,
			String tableName, String primaryKeyName, String primaryKeyValue,
			Vector<Vector<String>> vObjectRelated)
	{
		try
		{
			DDTP request = new DDTP();
			request.setObject("ipAddress", AppClient.getIpRemoteAddr());
			request.setString("primaryKeyValue", primaryKeyValue);
			request.setString("primaryKeyName", primaryKeyName);
			request.setString("tableName", tableName);
			request.setString("moduleName", moduleName);
			request.setObject("vObjectRelated", vObjectRelated);
			DDTP response = AppClient.sendRequest("CommonActionLog",
					"logBeforeUpdate", request);
			return (Vector) response.getReturn();
		}
		catch (Exception e)
		{
			e.printStackTrace();
			return null;
		}
	}
	
	public static void logActionAfterUpdate(Vector v)
	{
		try
		{
			DDTP request = new DDTP();
			request.setObject("ipAddress", AppClient.getIpRemoteAddr());
			request.setVector("vObjectRelated", v);
			AppClient.sendRequest("CommonActionLog", "logAfterUpdate", request);
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
	
	public static Vector<String> makeVector(String[] strArr)
	{
		
		if (strArr.length > 0)
		{
			Vector<String> vChild = new Vector<String>();
			for (int i = 0; i < strArr.length; i++)
			{
				vChild.add(strArr[i]);
			}
			return vChild;
		}
		return null;
	}
}
